<template>
  <div class="app">
    <!-- 头部 -->
    <van-nav-bar
      :title="title"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      fixed
    />
    <!-- 主体 -->
    <router-view></router-view>
    <!-- footer -->
    <van-tabbar v-model="active">
      <van-tabbar-item icon="home-o" to="/home">home</van-tabbar-item>
      <van-tabbar-item icon="search" to="/friend">friend</van-tabbar-item>
      <van-tabbar-item icon="friends-o" to="/crat">crat</van-tabbar-item>
      <van-tabbar-item icon="search" to="/search">search</van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
export default {
  data: () => ({
    title: sessionStorage.title || 'home',
    active: Number(sessionStorage.active) || 0
  }),
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    }
  },
  watch: {
    '$route.meta'(meta) {
      this.title = meta.title
      this.active = meta.active
      sessionStorage.title = meta.title
      sessionStorage.active = meta.active
    }
  }
}
</script>
<style lang="less">
.app {
  padding-top: 46px;
  padding-bottom: 50px;
}
</style>